package com.gzit.common.async;

import android.app.Activity;
import android.app.ProgressDialog;

import com.gzit.R;
import com.gzit.dialog.DialogUtils;
import com.gzit.utils.AndroidUtils;

public interface LoadingCallback {

	public static LoadingCallback EMPTY = new EmptyLoadingCallback();

	void showLoading();

	void hideLoading();

	void setMessage(String msg);

	public static class EmptyLoadingCallback implements LoadingCallback {

		@Override
		public void showLoading() {

		}

		@Override
		public void hideLoading() {

		}

		@Override
		public void setMessage(String msg) {

		}

	}

	// 默认锁住ui显示加载
	public static class DefaultLoadingCallback implements LoadingCallback {

		ProgressDialog loadingDialog;
		Activity ctx;

		public DefaultLoadingCallback(Activity ctx) {
			this.ctx = ctx;
		}

		@Override
		public void showLoading() {
			if (this.loadingDialog == null) {
				loadingDialog = DialogUtils.getProgressDlg(ctx,
						AndroidUtils.s(R.string.gzit_loading_dialog_content));
				loadingDialog.show();
			}

		}

		@Override
		public void hideLoading() {

			if (this.loadingDialog != null) {
				this.loadingDialog.dismiss();
			}
		}

		@Override
		public void setMessage(String msg) {
			if (this.loadingDialog != null) {

				this.loadingDialog.setMessage(msg);

			}

		}

	}

}
